package article

import "git.oschina.net/fuxiaohei/fuxiaohei-go.git/Core"

// get categories
func categoryGetList() []map[string]string {
	sql := Core.Sql("fuxiaohei_categories").Order("id ASC").Where("id > 0").Select()
	return Core.Db.All(sql)
}

// get category by id for an article
func categoryGetById(id string) map[string]string {
	sql := Core.Sql("fuxiaohei_categories").Where("id = ?").Select()
	return Core.Db.One(sql, id)
}

// get one category by slug
func categoryGetBySlug(slug string) map[string]string {
	sql := Core.Sql("fuxiaohei_categories").Where("slug = ?").Select()
	return Core.Db.One(sql, slug)
}

// refresh category's article count
func categoryCountUpdate() {
	sql := `UPDATE fuxiaohei_categories SET articles = (SELECT count(*) FROM fuxiaohei_articles WHERE fuxiaohei_articles.category = fuxiaohei_categories.id)`
	Core.Db.Exec(sql)
}

// get user for an article
func userGetOne(id string) map[string]string {
	sql := Core.Sql("fuxiaohei_users", "id,user,real_name,role_name").Where("id = ?").Select()
	return Core.Db.One(sql, id)
}

// get user by user name
func userGetByName(name string) map[string]string {
	sql := Core.Sql("fuxiaohei_users", "id,user,real_name,role_name").Where("user = ?").Select()
	return Core.Db.One(sql, name)
}


